package com.ruoyi.web.controller.base;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.BaseComp;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BaseStaff;
import com.ruoyi.system.service.IBaseStaffService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 驾驶员信息Controller
 * 
 * @author ruoyi
 * @date 2025-08-08
 */
@RestController
@RequestMapping("/driver/staff")
public class BaseStaffController extends BaseController
{
    @Autowired
    private IBaseStaffService baseStaffService;

    /**
     * 查询驾驶员信息列表
     */
    @PreAuthorize("@ss.hasPermi('driver:staff:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseStaff baseStaff)
    {
        startPage();
        List<BaseStaff> list = baseStaffService.selectBaseStaffList(baseStaff);
        return getDataTable(list);
    }

    /**
     * 导出驾驶员信息列表
     */
    @PreAuthorize("@ss.hasPermi('driver:staff:export')")
    @Log(title = "驾驶员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseStaff baseStaff)
    {
        List<BaseStaff> list = baseStaffService.selectBaseStaffList(baseStaff);
        ExcelUtil<BaseStaff> util = new ExcelUtil<BaseStaff>(BaseStaff.class);
        util.exportExcel(response, list, "驾驶员信息数据");
    }

    /**
     * 获取驾驶员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('driver:staff:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(baseStaffService.selectBaseStaffById(id));
    }

    /**
     * 新增驾驶员信息
     */
    @PreAuthorize("@ss.hasPermi('driver:staff:add')")
    @Log(title = "驾驶员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseStaff baseStaff)
    {
        return toAjax(baseStaffService.insertBaseStaff(baseStaff));
    }

    /**
     * 修改驾驶员信息
     */
    @PreAuthorize("@ss.hasPermi('driver:staff:edit')")
    @Log(title = "驾驶员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseStaff baseStaff)
    {
        return toAjax(baseStaffService.updateBaseStaff(baseStaff));
    }

    /**
     * 删除驾驶员信息
     */
    @PreAuthorize("@ss.hasPermi('driver:staff:remove')")
    @Log(title = "驾驶员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
            return toAjax(baseStaffService.deleteBaseStaffByIds(ids));
    }

    /**
     * 添加公司信息
     */
    @GetMapping("/company")
    // 直接接收url中的pageNum和pageSize参数（与前端传递的参数名一致）
    public TableDataInfo getCompanyList(
    ) 
    {
        // 直接使用参数调用服务层
        List<BaseComp> companyList = baseStaffService.getList();

        return getDataTable(companyList);
    }
}